<!--
 * @Author: wangjialing 524825477@qq.com
 * @Date: 2023-01-17 17:13:01
 * @FilePath: /qpcr-admin/src/views/reportManagement/index.vue
 * @Description:
-->
<template>
  <div class="app-container">
    <div>
      <el-input v-model="listQuery.username" style="width: 200px;" placeholder="用户名" clearable @clear="search" />
      <el-input v-model="listQuery.name" style="width: 200px;" placeholder="姓名" clearable @clear="search" />
      <el-input v-model="listQuery.phone" style="width: 200px;" placeholder="电话" clearable @clear="search" />
      <el-button type="primary" @click="search">搜索</el-button>
    </div>
    <table-list
      show-index
      :columns="columns"
      :page-size="listQuery.pageSize"
      :page-num="listQuery.currPage"
      :data="list"
      :total="total"
      style="margin-top: 20px;"
      @currentChange="handlePageChange"
    />
  </div>
</template>

<script>
import tableList from '@/components/table/tableList.vue'
import { qpcrreportProvider } from '@/api/api'

export default {
  name: 'ReportManagementIndex',
  components: {
    tableList
  },
  data() {
    return {
      listQuery: {
        currPage: 1,
        pageSize: 15,
        name: '',
        username: '',
        phone: ''

      },
      total: 1,
      columns: [
        { text: '报告编码', value: 'code' },
        { text: '用户名', value: 'username' },
        { text: '姓名', value: 'name' },
        { text: '电话', value: 'phone' },
        { text: '地址', value: 'address' },
        { text: '机器编码', value: 'deviceCode' },
        { text: '上传时间', value: 'updateDate' },
        { text: '操作', type: 'textButton', width: 150, list: this.operButton }
      ],
      list: []
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    search() {
      this.listQuery.currPage = 1
      this.getList()
    },
    getList() {
      const params = {
        limit: this.listQuery.pageSize.toString(),
        page: this.listQuery.currPage.toString(),
        username: this.listQuery.username,
        name: this.listQuery.name,
        phone: this.listQuery.phone
      }
      qpcrreportProvider.page(params).then(res => {
        if (res.code === 0) {
          this.list = res.data.list
          this.total = res.data.total
        }
      })
    },
    viewOne(val) {
      this.$router.push({ path: '/reportManagement/report/' + val.row.id })
    },
    deleteOne(val) {
      console.log(val.row, 'delete one')
      this.$confirm('是否确定删除该记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        qpcrreportProvider.deleteById({ id: val.row.id }).then((res) => {
          if (res.code === 0) {
            this.getList()
          }
        })
      })
    },
    operButton() {
      return [
        { value: '查看', click: this.viewOne },
        { value: '删除', click: this.deleteOne }
      ]
    },
    handlePageChange(val) {
      this.listQuery.currPage = val
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped></style>
